package com.yzy.soft.system.freemarker;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * mybatis-plus代码生成器(用于生成entity)<br>
 * 注意:<br>
 *     因为没用mybatis-plus的Service和Controller所以生成完之后要删掉TTT目录
 * @author stylefeng
 * @Date 2017/5/21 12:38
 */
public class Generator {


    private final static String[] table =new String[] { "Teammembers","Teammember"};
    private final static  String[] upperTableName=new String[]{"Teammembers","Teammember"};
    private final static String[] lowerTableName=new String[]{"teammembers","teammember"};



    public static void main(String[] args) throws Exception{

        TestCodeGenerateUtils TestCodeGenerateUtils=new TestCodeGenerateUtils(upperTableName,lowerTableName);
        TestCodeGenerateUtils.generate();
//          createEntity();
    }


    public static void createEntity(){

        AutoGenerator mpg = new AutoGenerator();
        // 全局配置
        GlobalConfig gc = new GlobalConfig();

        gc.setOutputDir("D:\\BaiduYunDownload\\liscw-parent\\IFI\\src\\main\\java");//这里写你自己的java目录
        gc.setFileOverride(true);//是否覆盖
        gc.setActiveRecord(true);
        gc.setEnableCache(false);// XML 二级缓存
        gc.setBaseResultMap(true);// XML ResultMap
        gc.setBaseColumnList(false);// XML columList
        gc.setAuthor("yinzhiyuan");
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();

        dsc.setDbType(DbType.MYSQL);
        dsc.setTypeConvert(new MySqlTypeConvert() {
            // 自定义数据库表字段类型转换【可选】
            @Override
            public DbColumnType processTypeConvert(String fieldType) {
                return super.processTypeConvert(fieldType);
            }
        });
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("root");

        dsc.setUrl("jdbc:mysql://127.0.0.1:3307/productpresentationsystem?characterEncoding=utf8");

        mpg.setDataSource(dsc);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setCapitalMode(true);
        //strategy.setTablePrefix(new String[]{"_"});// 此处可以修改为您的表前缀
        strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
        strategy.setInclude(table); // 需要生成的表
        mpg.setStrategy(strategy);
        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent(null);
        pc.setEntity("com.sinosoft.ifi.common.persistence.model");
        mpg.setPackageInfo(pc);
        // 执行生成
        mpg.execute();

    }





}